<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>群体感知写作</title>
<link href="/pad/resources/css/bootstrap.min.css" rel="stylesheet">
<link href="/pad/resources/css/bootstrap-select.min.css" rel="stylesheet">
<link href="/pad/resources/css/bootstrap-datetimepicker.min.css" rel="stylesheet">
<link href="/pad/resources/css/bootstrap-table.min.css" rel="stylesheet">
<link href="/pad/resources/css/bootstrap-editable.css" rel="stylesheet">
<link href="/pad/resources/css/style.css" rel="stylesheet">
</head>
<body>
	<nav class="navbar navbar-blue navbar-fixed-top" role="navigation">
		<div class="container bs-docs-container">
			<div class="navbar-header">
				<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-6">
					<span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span>
				</button>
				<h1>Pad</h1>
			</div>
			<ul class="nav navbar-nav">
				<li><a href="/pad">课程列表</a></li>
				<li><a href="/pad/comment_template.html">评论模板</a></li>
				<li class="active"><a href="#">视图管理</a></li>
			</ul>
			<ul class="nav navbar-nav navbar-right">
				<li class="dropdown"><a id="user" href="#" class="dropdown-toggle" data-toggle="dropdown">用户 <span class="caret"></span></a>
					<ul class="dropdown-menu" role="menu">
						<li><a href="/pad/logout">退出登录</a></li>
					</ul></li>
			</ul>
		</div>
	</nav>
	<div class="container bs-docs-container">
		<ol id="breadcrumb" class="breadcrumb">
			<li class="active">视图管理列表</li>
		</ol>
		<div id="toolbar"></div>
		<table id="data-table"></table>
	</div>
	<!-- 创建视图 modal -->
	<div id="createVisionModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal">
						<span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
					</button>
					<h4 class="modal-title" id="myModalLabel">创建视图</h4>
				</div>
				<div class="modal-body">
					<form id="createVision" role="form" action="/pad/addDictionary" method="post">
						<input type="hidden" name="code" value="VISION"/>
						<div class="form-group">
							<input class="form-control" name="dictTitle" type="text" placeholder="视图编号">
						</div>
						<div class="form-group">
							<input class="form-control" name="dictText" type="text" placeholder="视图名称">
						</div>
					</form>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
					<button type="button" class="btn btn-info" onclick="submitForm('#createVision','#createVisionModal');">创建</button>
				</div>
			</div>
		</div>
	</div>
	<script src="/pad/resources/js/jquery.min.js"></script>
	<script src="/pad/resources/js/jquery.form.min.js"></script>
	<script src="/pad/resources/js/bootstrap.min.js"></script>
	<script src="/pad/resources/js/bootstrap-table.min.js"></script>
	<script src="/pad/resources/js/bootstrap-select.min.js"></script>
	<script src="/pad/resources/js/bootstrap-editable.js"></script>
	<script src="/pad/resources/js/bootstrap-table-editable.js"></script>
	<script src="/pad/resources/js/bootstrap-datetimepicker.min.js"></script>
	<script>
	var currentUserId = "";
	var currentUserName = "";
	var currentCourseId = "";
	var currentCourseName = "";
	var currentAssignmentId = "";
	var currentAssignmentName = "";
	var currentActivityId = "";
	var currentActivityName = "";
	$(function(){
		$.ajax({
			url:'/pad/getSessionUser',
			success:function(user){
				currentUserId = user.id;
				currentUserName = user.realname;
				$("#user").html(user.realname+' <span class="caret"></span>');
			}
		});
		visionListView();
	});
	/**
	 * 提交表单
	 */
	function submitForm(formSelecter,modalSelecter){
		// 异步提交表单
	    $(formSelecter).ajaxSubmit({  
	        type:'post',
	        resetForm: true,
	        success:function(data){ 
	        	if(data=='success'){
	        		$('#data-table').bootstrapTable('refresh');
	        		$(modalSelecter).modal('hide');
	        	}else{
	        		alert(data);
	        	}
	        },
	        error:function(msg){
	        	alert(msg.statusText);
	        }
	    });  
	}
	function visionListView(){
		$('#toolbar').html('<button class="btn btn-info" data-toggle="modal" data-target="#createVisionModal"><span class="glyphicon glyphicon-plus"></span>创建视图</button>');
		$('#data-table').bootstrapTable('destroy');
		$('#data-table').bootstrapTable({
		    url: '/pad/getDictionary?code=VISION',
		    pagination:true,
		    search:true,
		    undefinedText:'',
		    striped:true,
		    showRefresh:true,
		    toolbar:'#toolbar',
		    idField:'id',
		    sortName:'dictTitle',
		    columns: [
		    	{field: 'dictTitle',title: '视图编号'},
		    	{field: 'dictText',title: '视图名称'},
		    	{field: 'op',title: '操作',width:100,formatter:function(value,row,index){
		    		return '<a href="javascript:deleteVision(\''+row.id+'\');" class="btn btn-danger btn-xs">删除</a>';
		    	}}]
		});
	}
	function deleteVision(visionId){
		$.ajax({
			url:'/pad/deleteDictionary?dictionaryId='+visionId,
			success:function(msg){
				if(msg=="success"){
					$('#data-table').bootstrapTable('refresh');
				}
			}
		});
	}
	</script>
</body>
</html>
